//线程的同步和互斥 以及生产者和消费者模型
#include "blockqueue.hpp"
struct ThreadData
{
    blockqueue<int> *bq;
    std::string name;
};

void* coumser(void*args)
{
    ThreadData *ctd =(ThreadData*)args;
    int i=0;
    while(true)
    {
        sleep(1);
        ctd->bq->Pop(&i);
        cout<<ctd->name<<"读取成功: "<< i <<endl;
        
    }

}
void* productor (void*args)
{
    ThreadData* ptd =(ThreadData*)args;
    int i =0;
    while(true)
    {
        
        ptd->bq->enqueue(i);
        cout<<ptd->name<<"插入成功: "<<i<<endl;
        i++;

    }

}
int main()
{
    pthread_t c,p;
    blockqueue<int>* bq=new blockqueue<int>();
    ThreadData ctd={bq,"消费者"};
    ThreadData ptd={bq,"生产者"};
    pthread_create(&c,nullptr,coumser,(void*)&ctd);
    pthread_create(&c,nullptr,productor,(void*)&ptd);



    pthread_join(c,nullptr);
    pthread_join(p,nullptr);
    return 0;
}